//数据库中的ID是自增的,为不与新生成的id冲突，临时ID采用负自增策略
export function getMinId(tree) {
    let minId = -1;
    if (tree.length === 0) {
        return minId;
    }

    tree.forEach(element => {
        if (element.id < minId) {
            minId = element.id;
        }

        if (element.children) {
            let minChildId = getMinId(element.children);
            if (minChildId < minId) {
                minId = minChildId;
            }
        }
    });
    return minId;
}

export function getMenuTreeParameters(menuTreeData) {
    let ret = [];
    if (menuTreeData.length === 0) {
        return ret;
    }

    menuTreeData.forEach(element => {
        //FIXME
        if (element.permType === "0" && element.parameters.length > 0) {
            ret.push(element);
        }

        if (element.children) {
            let childrenRet = getMenuTreeParameters(element.children);
            if (childrenRet.length > 0) {
                ret.push(...childrenRet);
            }
        }
    });
    return ret;
}
